<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-tickets"></i> 用户管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button>
            </div>
            <el-table :data="data" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column type="expand">
                        <template slot-scope="props">
                                <el-table :data="props.row.pl_list" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange2">
                                    <el-table-column type="selection" width="55"></el-table-column>    
                                    <el-table-column prop="sender_name" label="评论人" >
                                            </el-table-column>
                                            <el-table-column prop="content" label="内容" >
                                            </el-table-column>
                                            <el-table-column prop="time" label="发布时间" >
                                            </el-table-column>
                                            <el-table-column label="操作" width="180">
                                                    <template slot-scope="scope">
                                                        <el-button size="small" type="danger" @click="delpinglun(scope.$index, scope.row)">删除</el-button>
                                                    </template>
                                                </el-table-column>
                                </el-table>
                        </template>
                      </el-table-column>
                <el-table-column prop="name" label="发布人" >
                </el-table-column>
                <el-table-column prop="content" label="内容" >
                </el-table-column>
              
                <el-table-column prop="time" label="发布时间" ></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next"  :total="totalpage">
                </el-pagination>
            </div>
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
        </div>
</template>

<script>
    export default {
        data() {
            return {
                url: '/api/getmessage',
                tableData: [],
                cur_page: 1,
                multipleSelection: [],
                del_list: [],
                totalpage:0,
                delVisible: false,
                sender_letter:{

                },
                sendVisible:false,
                idx: -1
            }
        },
        created() {
            this.getData();
        },
        computed: {
            data() {
                return this.tableData
            }
        },
        methods: {
            // 分页导航
            handleCurrentChange(val) {
                this.cur_page = val;
                this.getData();
            },
            // 获取 easy-mock 的模拟数据
            getData() {
                // 开发环境使用 easy-mock 数据，正式环境使用 json 文件
            
                this.$axios.post(this.url, ).then((res) => {
                
                    this.tableData = res.data;
                })
              
                
            },
           
            formatter(row, column) {
                return row.address;
            },
            delAll() {
                this.delVisible = false
                this.$axios.post("/api/deletemessage", {
                    id: this.multipleSelection
                }).then((res) => {
                    console.log(res.data);
                    this.tableData = res.data;
                    this.$message.success('删除成功');
                })
                this.multipleSelection = [];
            },
            delpinglun(index, row) {
                console.log(row);
                
                this.delVisible = false
                this.$axios.post("/api/delpinglun", {
                    id: row.id
                }).then((res) => {
                    console.log(res.data);
                    this.tableData = res.data;
                    this.$message.success('删除成功');
                })
                this.multipleSelection = [];
            },
            handleSelectionChange(val) {
                
                this.multipleSelection = [];
                val.forEach(element => {
                    this.multipleSelection.push(element.id)
                });
            },
            handleSelectionChange2(val) {
                
                this.multipleSelection2 = [];
                val.forEach(element => {
                    this.multipleSelection2.push(element.id)
                });
            }
        }
          
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
</style>
